<?php

//
// +------------------------------------------------------------------------+
// | PHP Version 5.4                                                        |
// +------------------------------------------------------------------------+
// | Copyright (c) All rights reserved.                                     |
// +------------------------------------------------------------------------+
// | 世纪车来车往(北京）网络科技有限公司 版权所有！                               |
// | TEL:010-63732365  HOTLINE:400-6688-365  EMAIL:clcw@clcw.com.cn         |
// | $Revision: 1.0 $                                                       |
// +------------------------------------------------------------------------+
// | Author: xiangminghu@clcw.com.cn                                        |
// +------------------------------------------------------------------------+
//

namespace AuctionCore\Other;

/**
 * 碎片管理
 *
 * @author Xmh
 */
class Chip {

    private $Chip;

    public function __construct() {
        $this->Chip = M('Chip');
    }

    /**
     * 获取碎片列表
     * @param int $page
     * @param int $size
     * @param array $params
     */
    public function get_chip_list($page, $size, $params) {
        $page = (int) $page < 1 ? 1 : (int) $page;
        $size = (int) $size < 1 ? 10 : (int) $size;
        $map = array();
        $cols = 'id,name,content,desc,createtime,updatetime';
        $order = 'id DESC';
        $total = $this->Chip->where($map)->count();
        $list = $this->Chip->field($cols)
                ->where($map)
                ->limit($size)
                ->page($page)
                ->order($order)
                ->select();
        $result = array(
            'list' => $list,
            'total' => $total
        );
        return $result;
    }
    /**
     * 获取碎片信息
     * @param int $id
     * @return array
     */
    public function get_chip_info($id){
        return $this->Chip->find($id);
    }
    /**
     * 获取碎片信息
     * @param int $name
     * @return array
     */
    public function get_chip_info_byname($name){
        $condition['name'] = array('eq',$name);
        return $this->Chip->where($condition)->find();
    }
    
    /**
     * 更新碎片信息
     * @param array $data
     * @return int
     */
    public function update_chip($data){
        $data['updatetime'] = date("Y-m-d H:i:s",time());
        return $this->Chip->save($data);
    }
    
}
